public class ThreadDemo12 {
    public static void main(String[] args) {
        Object lock = new Object();

        Thread t1 = new Thread(()->{
            synchronized (lock) {
                System.out.println("wait 之前：");
                try {
                    lock.wait();
                    System.out.println("wait 之后");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

            }
        });

        Thread t2 = new Thread(()->{
            try {
                Thread.sleep(5000);
                synchronized (lock) {
                    System.out.println("notify之前");
                    lock.notify();
                    System.out.println("notify之后");
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

        });

        t1.start();
        t2.start();
    }
}
